var player = new PlayerPlane(...getPlayerPlaneInfo.call(playerPlaneInfo[0]), bulletInfo[0]);

renderStatistic(player.score, player.kill, player.blood);
window.onload = function () {
  // zhuxuanlv.play();
}

addEventListener('keydown', function (e) {
  e.keyCode == 38 && (player.up = true);
  e.keyCode == 40 && (player.down = true);
  e.keyCode == 37 && (player.left = true);
  e.keyCode == 39 && (player.right = true);
  e.keyCode == 32 && (player.shotFlag = true);
})
addEventListener('keyup', function (e) {
  e.keyCode == 38 && (player.up = false);
  e.keyCode == 40 && (player.down = false);
  e.keyCode == 37 && (player.left = false);
  e.keyCode == 39 && (player.right = false);
  e.keyCode == 32 && (player.shotFlag = false);
})

addEventListener('mousemove', function (e) {
  e.preventDefault(); // 阻止拖拽事件
})

var gameTimer = setInterval(() => {
  player.gameTime++;
  if (enemyPlaneArray.length >= 30) { return; }
  if (player.died) {
    clearInterval(gameTimer);
    return;
  }
  if (player.gameTime % 10 == 0) { // 每 10 秒 生成敌机数量 + 1
    player.enemyCreateSpeed++;
    player.blood++;
    renderStatistic(player.score, player.kill, player.blood);
    if (player.enemyCreateSpeed <= 3) { // 前 30 秒 每 10 秒加强一次子弹
      player.bullet = bulletInfo[player.enemyCreateSpeed - 1];
    } else {
      container.style.backgroundImage = 'url(./img/bg2.png)';
    }
  }
  for (var i = 0; i < player.enemyCreateSpeed; i++) {
    var num = getRandom(0, enemyPlaneInfo.length);
    var enemy = new EnemyPlane(...getEnemyInfo.call(enemyPlaneInfo[num]));
    enemy.blood += player.enemyCreateSpeed;
    enemyPlaneArray.push(enemy);
  }
}, 1000);

var isOver = setInterval(() => {
  player.check();
  if (player.died) {
    renderStatistic(player.score, player.kill, player.blood);
    clearInterval(isOver);
    showGame('游戏结束');
  }
}, 1000 / 60)
